# -*- coding: utf-8 -*-
"""
Created on Mon Apr  1 09:06:27 2024

@author: YANCL
"""
#%% BGR转灰度图像
import cv2

lena    = cv2.imread("photo\\lenaRGB.bmp")
convert = cv2.cvtColor(lena, cv2.COLOR_BGR2GRAY)  # BGR 2 GRAY
cv2.imshow("lena", lena)
cv2.imshow("gray", convert)

cv2.waitKey()
cv2.destroyAllWindows()

#%% BGR转RGB图像
import cv2

lena    = cv2.imread("photo\\lenaRGB.bmp")
convert = cv2.cvtColor(lena, cv2.COLOR_BGR2RGB)  # BGR 2 RGB
cv2.imshow("lena", lena)
cv2.imshow("RGB", convert)

cv2.waitKey()
cv2.destroyAllWindows()

#%% 灰度图像转换成BGR图像
import cv2

Goldhill = cv2.imread("photo\\Goldhill.bmp", cv2.IMREAD_UNCHANGED)
convert  = cv2.cvtColor(Goldhill, cv2.COLOR_GRAY2BGR)  # BGR 2 RGB
cv2.imshow("Goldhill", Goldhill)
cv2.imshow("BGR", convert)

print(Goldhill.shape)
print(convert.shape)    #打印出来 确实是三个通道

B, G, R = cv2.split(convert)
cv2.imshow("B", B)
cv2.imshow("G", G)
cv2.imshow("R", R)

cv2.waitKey()
cv2.destroyAllWindows()